<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="css/reset.css" type="text/css" />
<link rel="stylesheet" href="css/control.css" type="text/css"></link>
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="layer/layer.js"></script>
<style type="text/css">
.prompt_message {
	width: 400px;
	border: 1px solid #dedede;
	z-index: 1000;
}
</style>


</head>

<body>
	<div>
		<jsp:include page="publicPage.jsp" />
		<a href="#" class="font_color">
			<div class="col-md-3 col-md-offset-5 bgimg">
				<div>
					<div class="font_size">
						SearchBug <img src="images/bug.png"
							style="width:70px;height: 70px; margin-left:220px ;" />
					</div>
				</div>
		</a>
	</div>


	<div class="clear"></div>
	<div class="body">
		${userInfo.userid }
		<form action="bugInfo/buttonSearch" method="post" class="form-inline">
			<!-- id="form1"-->
			<input type="hidden" name="userid" value="${userInfo.userid }" /> <input
				type="text" name="description" class="form-control" id="search"
				style="width:400px" placeholder="你就随便写点啥就行" />
			<!-- 	<button class="btn btn-danger" style="margin-left: -10px;width:70px;">BUG</button> -->
			<input type="submit" class="btn btn-danger"
				style="margin-left: -10px;width:70px;" value="BUG" />
			<div class="clear"></div>
		</form>

		<!-- 提示信息 -->
		<div class="prompt_message"></div>
	</div>

	</div>

	<div class="foot">

		<div>
			<a href="#" class="a">设为首页</a> <a href="#" class="a">联系我们</a>
		</div>
		<div>&copy;2017版权所有；&nbsp;&nbsp;&nbsp;&nbsp;粤ICP证030173号</div>
	</div>

	<script>
		/* //<!-- var oForm = $("#form1");

		oForm.on("click", function() {
			window.location.href = "html/bugInfo.html";
			//alert("....................");
		})    */
		//搜索框修改事件  根据搜索框的class
		$(function() {

			//keyup键盘移开事件
			//将even(事件)作为参数,就是这个“点击”事件,通过这个even,可以获取到event.target,就是点击的对象等等属性

			

			$(".prompt_message").css("display", "none");
			$("#search").on("keyup", function(even) {
			var masges = $("#search").val();
				if (masges != "") {
					$(".prompt_message").css("display", "block");
				} else {
					$(".prompt_message").css("display", "none");
				}
				
				var userid=$("input[name=userid]").val();
				var bugId = $("input[name=bugId]").val();
				var str = $(this).val().trim();
				//console.log(str+"           "+even.keyCode+"           "+str.length);
				//如果str的长度不为零即为输入中
				if (str.length != 0) {
					$.ajax({
						url : "bugInfo/ajaxFind?description=" + str,
						success : function(json) {

							/*
							1.清空原有的数据
							2.解析msg
							3.绑定div
							 */
							var obj = JSON.parse(json);//解析msg
							$(".prompt_message").empty();//清空原有数据
							for(var i = 0 ;i <obj.length;i++){
							var o = obj[i]; 
							console.log(o);
							/* $(".prompt_message").append("<div><a href='bugInfo/' style='height:40px;' value='"+o[i]['']+"'>"+o[i]["description"]+"</a></div>"); */

$(".prompt_message").append("<a href='bugInfo/searchBug?userid="+userid+"&description="+o["description"]+"' style='text-align: left;padding:5px 3px;cursor: pointer;display:block;' class='solution' value="+o["bugId"]+">"+o['description']+"</a>"); 
							
							}
						}
					})

				} 

				

			})

		});
	</script>
</body>

</html>